class Solution {
    public int maxConsecutiveAnswers(String answerKey, int k) {
        int t = 0, f = 0;
        int ans = 0;
        int left = 0;
        for (int i = 0; i < answerKey.length(); i++) {
            if (answerKey.charAt(i) == 'T')
                t += 1;
            else
                f += 1;
            while (t > k && f > k) {
                // System.out.println(f);
                if (answerKey.charAt(left) == 'T')
                    t -= 1;
                else
                    f -= 1;
                left += 1;
            }
            ans = Math.max(ans, i - left + 1);
        }
        return ans;
    }
}